<template>
<div>
<van-nav-bar
  title="注册"
  left-arrow
  @click-left="onClickLeft"
/>
<van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="username"
    placeholder="请输入账号"
    :rules="[{ required: true, message: '请输入账号' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="password"
    placeholder="请输入账号"
    :rules="[{ required: true, message: '请输入账号' }]"
  />
  <div style="margin: 16px;">
    <van-button block type="primary" native-type="submit">注册</van-button>
  </div>
</van-form>
<router-link to='/regi'>已有帐号，去登陆</router-link>
</div>
</template>
<script>
import {login} from '../api/user'
// import {setToken} from '../until/stroage'
export default {
name:'LoginD',
 data() {
    return {
      username: '',
      password: '',
    };
  },
 components: {},

 methods: {
    async onSubmit(values) {
      const res = await login(values)
      // console.log(res.data.body.toke);
      if(res.data.status===200){
         this.$toast.success('注册成功')
         console.log(res.data);
        //  setToken(res.data.body.toke)
          setTimeout(()=>{
            this.$router.push('/regi')
          },300)
      }
    },
     onClickLeft() {
     this.$router.back()
    },
    
  },
}
</script>

<style scoped>
a{
    text-align: center;
    display: block;
    color: #666666;
}
</style>